package com.cskaoyan;

import com.cskaoyan.bean.EveryOne;
import com.cskaoyan.bean.LifeCycleBean;
import com.cskaoyan.demo1.Interface1;
import com.cskaoyan.demo1.Interface2;

/**
 * @author stone
 * @date 2022/12/20 00:20
 */
public class LifeCycleExecution {
    public static void main(String[] args) {
        LifeCycleBean lifeCycleBean = startLifeCycle(LifeCycleBean.class);
        System.out.println(lifeCycleBean.getNum());
    }

    private static <T> T startLifeCycle(Class<T> clazz) {
        EveryOne everyOne = new EveryOne();
        T instance = null;
        try {
            instance = clazz.newInstance();
            if (instance instanceof Interface1) {
                ((Interface1) instance).method1();
            }
            if (instance instanceof Interface2) {
                ((Interface2) instance).method2();
            }
            everyOne.method3(instance);
            everyOne.method4(instance);

        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return instance;
    }
}
